package web;/**
 * Created by aiqinag on 2017-06-22.
 */

import biz.Smbms_UserBiz;
import entity.Smbms_User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import java.io.UnsupportedEncodingException;
import java.util.Map;

/**O
 * 用户
 *
 * @author tom_plus
 * @date 2017-06-22-10:52
 */
@Controller
@RequestMapping("/user")
@SessionAttributes(types = Smbms_User.class)
public class Smbms_UserWeb {

    @Autowired
    public Smbms_UserBiz userbiz;

    @RequestMapping("/login")
    public String login(){
        return "login";
    }

    @RequestMapping("/loginUser")
    public String login(Smbms_User user, Map<String,Object> map, Model model) throws UnsupportedEncodingException {

        user.setUserName(new String(user.getUserName().getBytes("ISO-8859-1"),"UTF-8"));
        user.setUserPassword(new String(user.getUserPassword().getBytes("ISO-8859-1"),"UTF-8"));
        map.put("userName",user.getUserName());
        map.put("userPassword",user.getUserPassword());
        user = this.userbiz.login(map) ;
        if (user != null){
            System.out.println("用户登录成功！");
            model.addAttribute("userSession",user);
            return "jsp/frame";
        }else{
            System.out.println("用户登录失败！");
            return "forward:/user/login";
        }
    }
}
